package zzzhc.image.recognize;

import java.awt.image.BufferedImage;
import java.io.Serializable;

public class ImageRecognizer implements Serializable {

	private static final long serialVersionUID = 639133312306929513L;

	private Filter filter;

	private TokenRecognizer tokenRecognizer;

	public String recognize(BufferedImage image) {
		RecognizeContext context = new RecognizeContext(image);
		if (filter != null) {
			filter.doFilter(context);
		}
		StringBuilder s = new StringBuilder();
		for (ImageToken token : context.getTokens()) {
			Character c = tokenRecognizer.recognize(token);
			if (c == null) {
				s.append("");
			} else {
				s.append(c);
			}
		}
		return s.toString();
	}

	public Filter getFilter() {
		return filter;
	}

	public void setFilter(Filter filter) {
		this.filter = filter;
	}

	public TokenRecognizer getTokenRecognizer() {
		return tokenRecognizer;
	}

	public void setTokenRecognizer(TokenRecognizer tokenRecognizer) {
		this.tokenRecognizer = tokenRecognizer;
	}

}
